package com.chima.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.ProfessionalDao;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.domain.Professional;
import com.chima.service.ProfessionalService;

public class ProfessionalServiceImp implements ProfessionalService{
	private  ProfessionalDao professionalDao;
	
	public ProfessionalDao getProfessionalDao() {
		return professionalDao;
	}

	public void setProfessionalDao(ProfessionalDao professionalDao) {
		this.professionalDao = professionalDao;
	}

	public PageResponseBean findProfessional(PageRequestBean pageRequestBean) {
		
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total =professionalDao.findByTotalCount(pageRequestBean.getDept());
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Professional.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Professional> professionals= professionalDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(professionals);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveProfessional(Professional professional) {
		professionalDao.save(professional);
		
	}

	public void updateProfessional(Professional professional) {
		professionalDao.update(professional);
		
	}

	public void deleteProfessional(int id) {
		professionalDao.delete(id);
		
	}

	public Professional findByDepartAndName(int depart, int id) {
		
		return professionalDao.findByDepartAndName(depart, id);
	}

	public List<Professional> findByDepart(int depart) {
		
		return professionalDao.findByDepart(depart);
	}

	public List<Professional> ListAllProfessional() {
		
		return professionalDao.ListAllProfessional();
	}

	public Professional findById(int id) {
		
		return professionalDao.findById(id);
	}

	public Professional findByName(String name) {
		
		return professionalDao.findByName(name);
	}

	

}
